﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace _1065010_1065053_1065059_1065064
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btndangnhap_Click(object sender, EventArgs e)
        {
            TaiKhoan tk =new TaiKhoan();
            tk.tendangnhap=txtdangnhap.Text;
            tk.matkhau=txtmatkhau.Text;
            SqlConnection kn = DataProvider.ConnectionData();
            //string ten=string.Empty;
           
            SqlCommand lenh = new SqlCommand();
            lenh.CommandType = CommandType.Text;
            string sql = "select TenDangNhap, MatKhau from TaiKhoan where TenDangNhap=@TenDangNhap and MatKhau=@MatKhau";
            lenh.CommandText =sql;
            lenh.Connection = kn;
            SqlParameter pr = new SqlParameter("@TenDangNhap", SqlDbType.VarChar, 40);
            pr.Value = tk.tendangnhap;
            lenh.Parameters.Add(pr);

            pr = new SqlParameter("@MatKhau", SqlDbType.VarChar, 40);
            pr.Value = tk.matkhau;
            lenh.Parameters.Add(pr);

            DataTable bang = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(lenh);
            da.Fill(bang);
            
            if (bang.Rows.Count > 0)
            {
                Admin frm=new Admin();
                frm.Show();
            }
                else
            {
                MessageBox.Show("Ten Dang Nhap Hoac Mat Khau Khong Dung");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
